<template>
  <div class="game-container game-normal-container margin-88">
    <div class="header">
      <div class="title">【新游开荒——快来成为开荒第一人】</div>
      <router-link to="/shop" class="more">更多游戏</router-link>
    </div>
    <div class="SK-products-slider-container">
      <div class="product-slider-viewport">
        <div class="product-slider-content" style="left: 0px">
          <div
            class="game-block-container game-block-recommend"
            v-for="(game, index) in gameList"
            :key="game.id"
            @click="goGameDetail(game)"
          >
            <img :src="game.page" alt="" />
            <div class="price-block">
              <div class="sale" v-if="game.nowmoney == game.previousmoney">
                <div class="list-wrap list-wrap-single">
                  <span class="price">￥{{ game.nowmoney }}</span>
                </div>
              </div>
              <div class="sale" v-else>
                <span class="discount">-{{ game.sale }}%</span>
                <div class="list-wrap">
                  <span class="list-price">￥{{ game.previousmoney }}</span
                  ><span class="price">￥{{ game.nowmoney }}</span>
                </div>
              </div>
              <span class="iconfont platform_icon icon-steam_key"></span>
            </div>
            <div class="game-name">{{ game.name }}</div>
            <div class="recommend-text">
              <div class="recommend-game-name">{{ game.name }}</div>
              <div class="text" style="-webkit-box-orient: vertical">
                {{ game.introduce }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { reqGameList } from "@/api";
export default {
  name: "Games",
  data() {
    return {
      userInfo: {
        name: "",
        money: 0,
        page: "",
        phone: "",
        sex: "",
        state: "",
        password: "",
      },
      gameList: [],
      sale: 0,
    };
  },
  mounted() {
    this.getUserInfo();
    this.getGameList();
  },
  methods: {
    getUserInfo() {
      this.userInfo = JSON.parse(localStorage.getItem("userInfo"));
    },
    async getGameList() {
      let res = await reqGameList();
      if (res.code == 200) {
        this.gameList = res.data;
        for (var i = 0; i < this.gameList.length; i++) {
          this.gameList[i].sale = parseInt(
            (100 *
              (this.gameList[i].previousmoney - this.gameList[i].nowmoney)) /
              this.gameList[i].previousmoney
          );
        }
      }
    },
    goGameDetail(game) {
      this.$router.push({
        path: "/detail",
        query: {
          gamename: game.name,
        },
      });
    },
  },
};
</script>

<style>
.SK-products-slider-container > .swiper_container_con {
  position: relative !important;
}
.SK-products-slider-container > .swiper_container_con > .swiper-container {
  position: initial;
}
.SK-products-slider-container
  > .swiper_container_con
  > .swiper-container
  .swiper-button-prev,
.SK-products-slider-container
  > .swiper_container_con
  > .swiper-container
  .swiper-button-next {
  border-radius: 5px 5px 5px 5px;
  height: 60px;
  padding: 0 4px;
  background: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.5);
}
.SK-products-slider-container
  > .swiper_container_con
  > .swiper-container
  .swiper-button-prev {
  left: -45px;
}
.SK-products-slider-container
  > .swiper_container_con
  > .swiper-container
  .swiper-button-next {
  right: -45px;
}
.SK-products-slider-container
  > .swiper_container_con
  > .swiper-container
  .swiper-button-prev::after,
.SK-products-slider-container
  > .swiper_container_con
  > .swiper-container
  .swiper-button-next::after {
  font-size: 20px;
  font-weight: 600;
}

.SK-products-slider-container {
  position: relative;
}
.SK-products-slider-container .button {
  top: 50%;
  margin-top: -30px;
  position: absolute;
  font-size: 38px;
  color: rgba(255, 255, 255, 0.5);
  z-index: 1;
  padding: 0 10px;
  height: 60px;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  border-radius: 5px 5px 5px 5px;
}
.SK-products-slider-container .button:hover {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.2);
}
.SK-products-slider-container .prev-button {
  left: -45px;
}
.SK-products-slider-container .next-button {
  right: -45px;
}
.SK-products-slider-container .product-slider-viewport {
  overflow: hidden;
  width: 1200px;
  position: relative;
}
.SK-products-slider-container .product-slider-viewport .product-slider-content {
  width: 99999px;
  position: relative;
  transition: left 0.5s ease;
}
.SK-products-slider-container
  .product-slider-viewport
  .product-slider-content:after {
  content: " ";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}
.SK-flash-slider-container .product-slider-viewport .product-slider-content {
  width: 1200px;
}

.game-block-recommend:hover .recommend-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.game-block-recommend:hover .game-name {
  display: none;
}

.game-container {
  margin-top: 20px;
}

.game-container img {
  border-radius: 3px;
}

.game-container .header {
  margin-bottom: 20px;
  position: relative;
}

.game-container .header:after {
  content: " ";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}

.game-container .header .title {
  float: left;
  font-size: 18px;
  color: #fff;
}

.game-container .header .more {
  float: right;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
}

.game-bigdata-container {
  margin-top: 40px;
  overflow: hidden;
}

.game-bigdata-container .big_data_block_con .game-block-container {
  margin-bottom: 20px;
}

.game-bigdata-container
  .big_data_block_con
  .game-block-container:nth-child(4n) {
  margin-right: 0;
}

.new-cart-container .game-bigdata-container {
  margin-top: 50px;
  margin-bottom: 80px;
}

.new-order-complete-container .game-bigdata-container {
  margin-top: 30px;
  margin-bottom: 80px;
}

.game-block-container.show_cart .show_cart_btn {
  display: none;
  margin-left: 6px;
  width: 34px;
  height: 26px;
  text-align: center;
}

.game-block-container.show_cart:hover .show_cart_btn {
  display: inline-block;
}
</style>
